package com.fh.API_;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 方小勤
 * @version 1.0~
 */
/*
1.获取本机InetAddress对象 getLocalHost
2.根据指定主机名/域名获取ip地址对象getByName
3.获取InetAddress对象的主机名 getHostName
4.获取InetAddress对象的地址 getHostAddress
 */
public class inetAddress {
    public static void main(String[] args) throws UnknownHostException {
        //获取本机 InetAddress 对象 getLocalHost
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);
        //根据指定主机名/域名获取ip地址对象 getByName
        InetAddress host = InetAddress.getByName("DESKTOP");
        System.out.println(host);
        //根据 InetAddress 对象的主机名 getHostName
        InetAddress host2 = InetAddress.getByName("www.baidu.com");
        System.out.println(host2);
        String hostName = host2.getHostName();
        System.out.println(hostName);
        //获取 InetAddress 对象地址 getHostAddress
        String hostName1 = host2.getHostAddress();
        System.out.println(hostName1);
    }


}
